#include"../sock.h"

#define BUF_SIZE 500000
int len = sizeof(Sockaddr_un);

int main(int argc ,char ** argv)
{
    Sockaddr_un addr;
    if(remove(SV_SOCK_PATH) == -1 && errno != ENOENT)
        errExit("remove");
    ini_path(AF_UNIX,&addr,SV_SOCK_PATH);
    int sfd = socket(AF_UNIX,SOCK_STREAM,0);
    if(sfd == -1) errExit("socket");

    char buf[BUF_SIZE];
    if(bind(sfd,(struct sockaddr *) &addr,len) == -1)
        errExit("bind");
    if(listen(sfd,BACKLOG) == -1)
        errExit("listen");
    while(1){
        int cfd = accept(sfd,NULL,NULL);
        if(cfd == -1) errExit("accept");
        int numRead = 0 ;
        while( (numRead = read(cfd,buf,sizeof(buf))) > 0)
            ;
        if(numRead == -1)
            errExit("read");
    }
    return 0;
}